import {defineConfig, loadEnv} from 'vite'
import path from 'path'
import createVitePlugins from './vite/plugins'
import {resolve} from 'path';

// https://vitejs.dev/config/
export default defineConfig(({mode, command}) => {
        const env = loadEnv(mode, process.cwd())
        const {VITE_APP_ENV} = env

        return {
            base: "./",	// 新增
            envDir: 'config/env',
            server: {
                port: 25000 //指定端口号
            },
            plugins: createVitePlugins(env, command === 'build'),
            build: {
                chunkSizeWarningLimit: 2000, // 更新此值以根据需要进行警告调整
                rollupOptions: {
                    input: {
                        // 配置所有页面路径，使得所有页面都会被打包
                        index: resolve(__dirname, 'index.html'),
                        notice: resolve(__dirname, 'notice/index.html'),
                    }
                }
            },
            resolve: {
                // https://cn.vitejs.dev/config/#resolve-alias
                alias: {
                    // 设置路径
                    '~': path.resolve(__dirname, './'),
                    // 设置别名
                    '@': path.resolve(__dirname, './src')
                },
                // https://cn.vitejs.dev/config/#resolve-extensions
                extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
            },
            //fix:error:stdin>:7356:1: warning: "@charset" must be the first rule in the file
            css: {
                postcss: {
                    plugins: [
                        {
                            postcssPlugin: 'internal:charset-removal',
                            AtRule: {
                                charset: (atRule) => {
                                    if (atRule.name === 'charset') {
                                        atRule.remove();
                                    }
                                }
                            }
                        }
                    ]
                }
            }
        }
    }
)
